from web import models


def get_subnet_queryset():
    pid_queryset = models.IpSubnet.objects.filter(pid_id__isnull=False).values('pid__id').distinct()
    pid_list = [item['pid__id'] for item in pid_queryset]
    queryset1 = models.IpSubnet.objects.exclude(id__in=pid_list).filter(pid__isnull=True).all()
    queryset2 = models.IpSubnet.objects.filter(pid_id__isnull=False).all()
    return queryset1 | queryset2
